package com.xl.cloud.netty.nio;

import java.nio.ByteBuffer;

/**
 * @Author XiangLiang
 * @Since 2025/1/9 14:06
 * @Description: NIOByteBufferPutGet类
 */
public class NIOByteBufferPutGet {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(64);

        // 类型化方式放入数据
        byteBuffer.putInt(100);
        byteBuffer.putLong(987654321L);
        byteBuffer.putShort((short) 9);
        byteBuffer.putChar('尚');

        // 切换到读模式
        byteBuffer.flip();
        System.out.println("After flip:");

        System.out.println("int: " + byteBuffer.getInt());
        System.out.println("long: " + byteBuffer.getLong());
        System.out.println("short: " + byteBuffer.getShort());
        System.out.println("char: " + byteBuffer.getChar());
    }
}
